import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:sainbainu/common/values/sizes.dart';

import 'package:nested_scroll_view_plus/nested_scroll_view_plus.dart';
import 'package:sainbainu/view/user_detail/comment_forward/view.dart';
import 'package:sainbainu/view/user_detail/like/view.dart';
import 'package:sainbainu/view/user_detail/widgets/custom_sliver_app_bar.dart';
import 'package:sainbainu/view/user_detail/widgets/custom_tab_bar.dart';
import 'package:sainbainu/view/user_detail/work/view.dart';

import 'index.dart';
import 'widgets/head_content.dart';

class UserDetailPage extends GetView<UserDetailController> {
  const UserDetailPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<UserDetailController>(
      builder: (_) {
        return Scaffold(
          body: _buildNestedScrollView(),
        );
      },
    );
  }

  /// 主视图
  Widget _buildNestedScrollView() {
    return NestedScrollViewPlus(
      controller: controller.state.scrollController,
      overscrollBehavior: OverscrollBehavior.outer,
      headerSliverBuilder: (context, innerScrolled) {
        return [
          CustomSliverAppBar(
            userInfo: controller.state.otherUserInfo,
            titleChild: GetBuilder<UserDetailController>(
              id: 'userDetail',
              builder: (_) => Text(_.state.otherUserInfo.nickName ?? ''),
            ),
            headContent: GetBuilder<UserDetailController>(
              id: 'userDetail',
              builder: (_) => HeadContent(
                userInfo: _.state.otherUserInfo,
                onDoFollowTap: () => _.onFollowHandle(),
                onFansTap: () => _.toFansPage(),
                onFollowTap: () => _.toFollowPage(),
              ),
            ),
            bottom: PreferredSize(
              preferredSize: Size(Get.width, kProfileTabbarHeight),
              child: const CustomTabBar(),
            ),
            onBack: controller.handleBack,
          ),
        ];
      },
      body: _buidBody(),
    );
  }

  /// 正文
  Widget _buidBody() {
    return TabBarView(
      controller: controller.state.tabController,
      children: [
        Container(
          key: const PageStorageKey<String>('work'),
          child: const WorkPage(),
        ),
        Container(
          key: const PageStorageKey<String>('like'),
          child: const LikePage(),
        ),
        Container(
          key: const PageStorageKey<String>('commentForward'),
          child: const CommentForwardPage(),
        ),
      ],
    );
  }
}
